import 'package:flutter/material.dart';
import 'package:ljy_flutter/Inherited/inherited_widget_state.dart';

class InheritedHomeScreen extends StatelessWidget {
  const InheritedHomeScreen({super.key});

  @override
  Widget build(BuildContext context) {
    final countIW = CounterInheritedWidget.of(context);
    return Scaffold(
      appBar: AppBar(title: Text('inherited widget state demo')),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          SizedBox(
            width: double.infinity,
            child: Center(child: Text('demo demo')),
          ),
          Text(
            'current counter = ${countIW?.counter ?? -1}',
            style: Theme.of(context).textTheme.bodyMedium,
          ),
          OutlinedButton(
            onPressed: () {
              countIW?.incrementCounter();
            },
            child: Text('点我加加'),
          ),
        ],
      ),
    );
  }
}
